import pyautogui as pg
import os
import time
import pyperclip
import requests
import json
import psutil
import sys
import threading
import win32gui
import win32con
import win32clipboard as w



# 扫描指定目录下的文件，运行名称里有QDJJ或者以斯维尔清单开头的文件
def open_software(dir_path) :
    file_list = os.listdir(dir_path)
    list = []
    for file_name in file_list :
        if (file_name.startswith("斯维尔清单") or "QDJJ" in file_name):
            list.append(file_name)
    os.startfile(dir_path + "\\" + list[0])

# 桌面软件地址
software_path = 'D:\\'
# 打开导出桌面软件
open_software(software_path)

time.sleep(15)
tips = win32gui.FindWindow(None, "提示")
if tips:
    # win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
    print(f"窗口句柄为：{tips}")
    # win32gui.SetForegroundWindow(tips)
    title = win32gui.GetWindowText(tips)
    clsname = win32gui.GetClassName(tips)
    print(title + clsname)
    win32gui.SendMessage(tips, win32con.WM_CLOSE, 0, 0)
else:
    print("tips : 未找到指定窗口")

time.sleep(3)

tutor = win32gui.FindWindow(None, "新建向导")
if tutor:
    win32gui.SendMessage(tutor, win32con.WM_CLOSE, 0, 0)
    print(f"窗口句柄为：{tutor}")
else:
    print("新建向导 : 未找到指定窗口")



hwnd = win32gui.FindWindow(None, "斯维尔清单计价 TH-BQ2016 学习版")
if hwnd:
    # win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
    print(f"窗口句柄为：{hwnd}")
else:
    print("未找到指定窗口")

menu = win32gui.GetMenu(hwnd)
menu1 = win32gui.GetSubMenu(menu, 0)#第几个菜单
cmd_ID = win32gui.GetMenuItemID(menu1, 1)#第几个子菜单
win32gui.PostMessage(hwnd, win32con.WM_COMMAND, cmd_ID, 0)
time.sleep(2)
open = win32gui.FindWindow(None, "打开")
if open:
    # win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
    print(f"打开窗口句柄为：{open}")
    time.sleep(1)
    win32gui.SetForegroundWindow(open)
else:
    print("打开未找到指定窗口")

pyperclip.copy(r'D:\rpa\1877275862835201.Qdg4')
pg.hotkey('Ctrl','v')
time.sleep(2)
pg.hotkey("Enter")
time.sleep(1)
pg.hotkey("Enter")
time.sleep(1)
pg.hotkey("Enter")
